package com.yuqing.sentimentapp.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuqing.sentimentapp.R;

/**
 * Created by hqd on 2017/4/10.
 */
public class UpdateAppDialog extends Dialog implements View.OnClickListener {
    private View rootView;
    private TextView message;
    private ImageView updateButton;
    private ImageView closeButton;
    private ButtonListener update;
    private ButtonListener close;
    private TextView tip;

    public UpdateAppDialog(Context context) {
        super(context, R.style.dialog);
        init(context);
    }

    public UpdateAppDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    private void init(Context context) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setCanceledOnTouchOutside(true);
        rootView = LayoutInflater.from(context).inflate(R.layout.dialog_update_app, null);
        setContentView(rootView);
        message = (TextView) rootView.findViewById(R.id.textview_dialog_msg);
        tip = (TextView) rootView.findViewById(R.id.textview_dialog_tip);
        updateButton = (ImageView) rootView.findViewById(R.id.iv_update);
        updateButton.setOnClickListener(this);
        closeButton = (ImageView) rootView.findViewById(R.id.iv_close);
        closeButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_update:
                update.buttonOkClick(this);
                break;
            case R.id.iv_close:
                close.buttonOkClick(this);
                break;
            default:
                break;
        }
    }

    public void setCancleVisiable(int visiable) {
        if (closeButton != null) closeButton.setVisibility(visiable);
    }
    public void setMessage(String message) {
        this.message.setText(message);
    }

    public void setCancleButtonListener(ButtonListener buttonListener) {
        this.close = buttonListener;
    }

    public void setOkButtonListener(ButtonListener buttonListener) {
        this.update = buttonListener;
    }

    public interface ButtonListener {
        void buttonOkClick(Dialog dialog);
    }
}
